﻿using GYCTOAManagementSystemNewApi.Controllers;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using GYCTOAManagementSystemNewApi.Controllers.PublicController;
using Microsoft.Extensions.FileProviders;
using Microsoft.OpenApi.Models;
using System;
using System.IO;
using static System.Net.WebRequestMethods;

namespace GYCTOAManagementSystemNewApi.Public
{   
    public static class Bootstrapper
    {
        public static IApplicationBuilder UseStaticFiles(this IApplicationBuilder app, IConfiguration configuration)
        {

            var path = PublicMethodApiController.StaticFilePath;
            var  RequestPath = "/"+ PublicMethodApiController.FileloadMapping;
            string currentPath = System.IO.Directory.GetCurrentDirectory();
   
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
             {
                app = app.UseStaticFiles(new StaticFileOptions
                {
                    FileProvider = new PhysicalFileProvider(path),
                    RequestPath = RequestPath
                });
            }
            return app;
        }
        /// <summary>
        /// 添加Swagger
        /// </summary>
        /// <param name="services"></param>
        public static void AddSwaggerGen(this IServiceCollection services)
        {
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApi", Version = "v1" });
                string[] xmls = Directory.GetFiles(AppContext.BaseDirectory, "oa.*.xml");
                foreach (string xml in xmls)
                {
                    options.IncludeXmlComments(xml);
                }
            });
        }
    }
}
